package com.android.gufengmall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.gufengmall.R;
import com.android.gufengmall.bean.AddressBean;

import java.util.List;

public class CartAddressAdapter extends RecyclerView.Adapter<CartAddressAdapter.CartAddressViewHolder> {

    private Context mContext;
    private List<AddressBean> mAddressBeans;

    public CartAddressAdapter(Context context, List<AddressBean> addresses) {
        mContext = context;
        mAddressBeans = addresses;
    }

    @NonNull
    @Override
    public CartAddressViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new CartAddressViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_address,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull CartAddressViewHolder holder, int position) {
        AddressBean addressBean = mAddressBeans.get(position);

        holder.mTvAddress.setText(addressBean.getAddress());
    }

    @Override
    public int getItemCount() {
        return mAddressBeans.size();
    }

    public class CartAddressViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTvAddress;

        public CartAddressViewHolder(@NonNull View itemView) {
            super(itemView);

            mTvAddress = itemView.findViewById(R.id.tv_address);
        }
    }
}
